<?php 
	include ('base.php');
	Class InformationAction extends Action{
		Public function insert() {
			/*
			 	照片上传没写!!
					照片后缀名判断! 只能上传图片格式,否则报错!
			 */
			if($_POST['submit']=='提交'){
				$info = M('information');

				$data = array(
						'name' => $_POST['name'],
						'sex' => $_POST['sex'],
						'date' => $_POST['date'],
						'num' => $_POST['num'],
						'department' => $_POST['department'],
						'class' => $_POST['class'],
						'photo' => $_POST['photo'],
						'place' => $_POST['place'],
						'comeDate' => $_POST['comeDate']
					);
				$ValidationModel = new ValidationModel();
				$valdation = $ValidationModel->validation($data);

				if($_POST['name']==''||$_POST['sex']==''||$_POST['date']==''||$_POST['num']==''||$_POST['department']==''||$_POST['class']==''||$_POST['photo']==''||$_POST['place']==''||$_POST['comeDate']==''){
					$this->error('都是必填项!,请补全!');
				}
				else if ($ValidationModel->Duplicate('Information','num',$_POST['num'])){
					$this->error('此学生已录入,无法重复录入!');
				}
				else if ($valdation!=-1){
					$this->error($valdation);
				}
				else{
					if($add = $info->data($data)->add()) {
						$this->success("信息录入成功!");
					}
				}
			}
			else{
				$this->display();
			}
			
		}


		Public function update() {
			$ValidationModel = new ValidationModel();
			$falseArr = array('0'=>'');	//整个假数组让没查询时正常显示页面!
			$this->assign('stu',$falseArr);
			if($_POST['submit']=='提交'){
				if($_POST['name']==''||$_POST['sex']==''||$_POST['date']==''||$_POST['num']==''||$_POST['department']==''||$_POST['class']==''||$_POST['photo']==''||$_POST['place']==''||$_POST['comeDate']==''){
				$this->error('都是必填项!,请补全!');
				}

				$info = M('information');
				$data = array(
						'name' =>$_POST['name'],
						'sex' =>$_POST['sex'],
						'date' =>$_POST['date'],
						'department' =>$_POST['department'],
						'class' => $_POST['class'],
						'photo' =>$_POST['photo'],
						'place' =>$_POST['place'],
						'comeDate' =>$_POST['comeDate'],
					);
				if($update = $info ->data($data) ->where("num=$_POST[num]")->save()){
					$this->success('信息修改成功!',"__GROUP__/Information/update");
				}
				else{
					$this->error('wrong');
				}
			}
			else if ($_POST['upd_sel']=='查询'){
				$stu = $ValidationModel->Duplicate('Information','num',$_POST['num']);
				if ($stu==null){
						$this->error('不存在这个学生,无法更改!');
				}else{
					$this->assign('stu',$stu);	//※※※这句简写就是$this->stu;
					$this->display();
				}
			}
			else{
				/*
				 	遍历现有信息
				 */
				$this->display();
			}
			
		}


		Public function delete() {
			$ValidationModel = new ValidationModel();
			$info = M('information');
			if($delete = $info->where("num=$_POST[num]")->delete()){
				$this->success('信息删除成功!');
			}
			else if(!$ValidationModel->Duplicate('Information','num',$_POST['num'])){
				$this->error('查无此人!');
			}
		}

		// Public function select_dis() {
		// 	$this->display();
		// }
		Public function select() {
			$ValidationModel = new ValidationModel();
			if($_POST['submit']=='查询'){
				if(!$ValidationModel->Duplicate('Information','num',$_POST['num'])){
					echo "<script type='text/javascript'>window.alert = function(str){return ;}</script>";
					$this->error('查无此人!');
				}
				else{
					$info = M('information');
					$this->select = $info->where("num=$_POST[num]")->select();
					echo "<script type='text/javascript'>alert('查询成功!');</script>";
				}
			}	
			
				$this->display();
			
			
		}

		Public function selClass() {
			$where['department']=$_POST['department'];
			$where['class']=$_POST['class'];
			$info = M('information');
			$this->selClass = $info->where($where)->select();
			$this->display();
		}	
	}
 ?>



